﻿@model NAccounting.Models.LotListModel

@{
    ViewBag.Title = "Index";
}

<script language="javascript">
    $(function () {
        $("#grid").jqGrid({
            datatype: "json",
            url: "/Lot/GetAllLots/",
            postData: {
                LotStateOption: function () { return $("#LotState").val(); },
                DateOption: function () { return $("#SelectedDateOption").val(); }
            },
            mtype: 'GET',
            rowNum: 30,
            pager: '#pager',
            viewrecords: true,
            sortname: 'Description',
            height: 258,
            sortorder: "desc",
            colNames: ["id", "", "Descrição", "Período", "Crédito", "Débito", "Abertura", "Fechamento", "canEditLot"],
            colModel: [{ name: "Id", width: 1, hidden: true, key: true },
                       { name: "actions", width: 8, resizable: false, sortable: false, align: 'center' },
                       { name: "Description", width: 120, sortable: false },
                       { name: "Period", width: 42, sortable: false, align: 'right' },
                       { name: "TotalCredit", width: 28, sortable: false, align: 'right' },
                       { name: "TotalDebit", width: 28, sortable: false, align: 'right' },
                       { name: "OpenDate", width: 28, sortable: false, align: 'right' },
                       { name: "CloseDate", width: 28, sortable: false, align: 'right' },
                       { name: "canEditLot", width: 1, hidden: true }
            ],
            autowidth: true,
            gridComplete: function () {
                var rows = $("#grid").jqGrid('getRowData');

                for (var i = 0; i < rows.length; i++) {
                    var row = rows[i];
                    var actions = "";

                    if (row['canEditLot'] == "true") {
                        var address = "/Lot/Edit/" + row['Id'];
                        editButton = "<button class='button-icon-edit-icon-only' onclick=\"window.location.href = '" + address + "'\">Editar</button>";
                        actions = editButton;
                    }

                    $("#grid").jqGrid('setRowData', row['Id'], { actions: actions });
                }

                environment.refreshStyles();
            }
        });

        $("#messageContainer").messageContainer();

        $("#LotState, #SelectedDateOption").change(function () {
            $('#grid').trigger('reloadGrid');
        });
    });
</script>

<div class="content-left">
    @Html.Partial("ContentLeftPartial")
</div>
<div class="content-right">
    <h2>Index</h2>
    <p>
        @Html.ActionLink("Create New", "Edit", null, new { @class = "button-icon-plus" })
    </p>
    <div>
        @Html.LabelFor(model => model.LotState) @Html.DropDownList("LotState", Model.LotState, new { @class = "searchable-combobox" })
        @Html.LabelFor(model => model.SelectedDateOption) @Html.DropDownListFor(model => model.SelectedDateOption, Model.DateOptions, new { @class = "searchable-combobox" })
    </div>
    <div style="margin-top:5px;">
        <table id="grid">
        </table>
         <div id="pager"></div>
    </div>
    <p>&nbsp;</p>
</div>
